/**
 * File: Node2ArcCountMarker.java
 * Created by: mhaimel
 * Created on: Mar 26, 2010
 * CVS:  $Id: Node2ArcCountMarker.java 1.0 Mar 26, 2010 11:01:36 AM mhaimel Exp $
 */
package uk.ac.ebi.curtain.model.graph.curtain.filter;

import java.util.List;

import uk.ac.ebi.curtain.model.graph.Arc;
import uk.ac.ebi.curtain.model.graph.Node;
import uk.ac.ebi.curtain.model.graph.GraphAccess.TouchEach;
import uk.ac.ebi.curtain.model.graph.curtain.ContigInfo;
import uk.ac.ebi.curtain.model.graph.curtain.ReadWrapper;

/**
 * @author mhaimel
 *
 */
public class Node2ArcCountMarker implements TouchEach<Node<ContigInfo, ReadWrapper>> {

	@Override
	public void touch(Node<ContigInfo, ReadWrapper> node) {
		processEdge(node.getLeft());
		processEdge(node.getRight());
	}
	
	private void processEdge(List<Arc<ContigInfo, ReadWrapper>> arcs){
		if(arcs.isEmpty()){
			return;
		}
		int size = arcs.size();
		for(Arc<ContigInfo, ReadWrapper> a : arcs){
			int tmp = 0;
			do{
				if(a.getStatus().compareAndSet(tmp, size)){
					break;
				}
				tmp = a.getStatus().get();
				if(tmp >= size){
					break;
				} 
				tmp = size;
			}while(true);
		}
	}
}
